<?php
$strDBSite = trim($_SERVER[argv][1]);
$strDBName = trim($_SERVER[argv][2]);

if($strDBSite == "")exit("No DB Site!!\n");
if($strDBName == "")exit("No DB Name!!\n");

$_BetDBHost = $strDBSite;
$_BetDBUser = "kacino";
$_BetDBPass = "cyriac_0426";

if (! $_Conn = @mysql_connect($_BetDBHost, $_BetDBUser, $_BetDBPass))exit("Can't connect to DB!!\n");

$strSQL = "CREATE DATABASE `".$strDBName."`";
mysql_query($strSQL);
print "DB OK!!\n";
@mysql_close($_Conn);


//建立歷史查詢資料庫
$_BetDBHost = "192.168.5.124";
$_BetDBUser = "kacino";
$_BetDBPass = "cyriac_0426";
$_BetDBName = "betLuckyballcc";

if (! $_Conn = @mysql_connect($_BetDBHost, $_BetDBUser, $_BetDBPass))exit("Can't connect to DB!!\n");

$strSQL = "CREATE DATABASE `".$strDBName."`";
mysql_query($strSQL);

if (! @mysql_select_db($strDBName, $_Conn))exit("Can't select to ".$strDBName." DB!!\n");

//創建  Table
$strSQL = "
				CREATE TABLE `bet_BetList` (
				  `ID` int(11) NOT NULL default '0',
				  `LottoID` int(11) NOT NULL default '0',
				  `LType` tinyint(4) NOT NULL default '1',
				  `Bet_Type` tinyint(11) NOT NULL default '0',
				  `GambleID` int(11) NOT NULL default '0',
				  `Number` tinyint(11) NOT NULL default '0',
				  `OddsID` int(11) NOT NULL default '0',
				  `OddsID2` int(11) NOT NULL default '0',
				  `Odds` float NOT NULL default '0',
				  `Odds2` float NOT NULL default '0',
				  `MemID` int(11) NOT NULL default '0',
				  `MemExchangeRate` float NOT NULL default '1',
				  `MemCurrency` tinyint(11) NOT NULL default '1',
				  `MemStake` int(11) NOT NULL default '0',
				  `MemPayOff` float NOT NULL default '0',
				  `MemResult` double NOT NULL default '0',
				  `MemCommission` float NOT NULL default '0',
				  `SubID` int(11) NOT NULL default '0',
				  `SubIncome` double NOT NULL default '0',
				  `SubCommission` float NOT NULL default '0',
				  `SubResult` double NOT NULL default '0',
				  `SubRate` float NOT NULL default '1',
				  `SubRateResult` double NOT NULL default '0',
				  `MainID` int(11) NOT NULL default '0',
				  `MainCommission` float NOT NULL default '0',
				  `MainResult` double NOT NULL default '0',
				  `MainRate` float NOT NULL default '0',
				  `MainRateResult` double NOT NULL default '0',
				  `StockID` int(11) NOT NULL default '0',
				  `StockCommission` float NOT NULL default '0',
				  `StockResult` double NOT NULL default '0',
				  `StockRate` float NOT NULL default '0',
				  `StockRateResult` double NOT NULL default '0',
				  `DirectorID` int(11) NOT NULL default '0',
				  `DirectorCommission` float NOT NULL default '0',
				  `DirectorResult` double NOT NULL default '0',
				  `DirectorRate` float NOT NULL default '0',
				  `DirectorRateResult` double NOT NULL default '0',
				  `PayupDate` date NOT NULL default '0000-00-00',
				  `isPayOff` tinyint(4) NOT NULL default '0',
				  `WagerType` tinyint(4) NOT NULL default '0',
				  PRIMARY KEY  (`ID`),
				  KEY `MainID` (`MainID`),
				  KEY `SubID` (`SubID`),
				  KEY `MemID` (`MemID`),
				  KEY `StockID` (`StockID`),
				  KEY `Bet_Type` (`Bet_Type`),
				  KEY `GambleID` (`GambleID`),
				  KEY `PayupDate` (`PayupDate`),
				  KEY `Number` (`Number`)
				) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='下注單';
";
if(!mysql_query($strSQL, $_Conn)){
	print $strSQL."\n";
	print "LogRecord Error :".mysql_error($_Conn)."<br />\n";
}

$strSQL = "
				CREATE TABLE `bet_BetListContent` (
				  `ID` int(11) NOT NULL auto_increment,
				  `GameDate` date NOT NULL default '0000-00-00',
				  `BetDate` date NOT NULL default '0000-00-00',
				  `BetTime` time NOT NULL default '00:00:00',
				  `Content` text NOT NULL,
				  `checkkey` varchar(20) NOT NULL default '',
				  `GambleType` tinyint(4) NOT NULL default '0',
				  `MemAccount` varchar(15) NOT NULL default '',
				  `isBlack` tinyint(4) NOT NULL default '0',
				  `NNWin` tinyint(4) NOT NULL default '0',
				  `NSWin` tinyint(4) NOT NULL default '0',
				  `JoinNumber` varchar(150) NOT NULL default '',
				  `OneStake` int(11) NOT NULL default '0',
				  `SuppleID` int(11) NOT NULL default '0',
				  PRIMARY KEY  (`ID`),
				  UNIQUE KEY `checkkey` (`checkkey`),
				  KEY `SuppleID` (`SuppleID`)
				) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='下注單內容';
";
if(!mysql_query($strSQL, $_Conn)){
	print $strSQL."\n";
	print "LogRecord Error :".mysql_error($_Conn)."<br />\n";
}

$strSQL = "
				CREATE TABLE `bet_Member` (
				  `ID` int(11) NOT NULL auto_increment,
				  `Account` char(15) NOT NULL default '',
				  `Password` char(50) NOT NULL default '',
				  `Name` char(20) NOT NULL default '',
				  `MemberGroup` int(11) NOT NULL default '0',
				  `ParentID` int(11) NOT NULL default '0',
				  `SubID` int(11) NOT NULL default '0',
				  `MainID` int(11) NOT NULL default '0',
				  `StockID` int(11) NOT NULL default '0',
				  `DirectorID` int(11) NOT NULL default '0',
				  `AddDate` date NOT NULL default '0000-00-00',
				  `AddTime` time NOT NULL default '00:00:00',
				  PRIMARY KEY  (`ID`),
				  KEY `Account` (`Account`),
				  KEY `MemberGroup` (`MemberGroup`),
				  KEY `Password` (`Password`),
				  KEY `ParentID` (`ParentID`),
				  KEY `SubID` (`SubID`),
				  KEY `MainID` (`MainID`),
				  KEY `StockID` (`StockID`),
				  KEY `DirectorID` (`DirectorID`)
				) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='會員資料';
";
if(!mysql_query($strSQL, $_Conn)){
	print $strSQL."\n";
	print "LogRecord Error :".mysql_error($_Conn)."<br />\n";
}

print "History DB OK!!\n";
@mysql_close($_Conn);
?>
